package cn.sciento.starter.social.core.common.connect;

import cn.sciento.starter.social.core.common.api.SocialApi;
import cn.sciento.starter.social.core.provider.Provider;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionData;
import org.springframework.social.connect.support.OAuth2ConnectionFactory;
import org.springframework.social.oauth2.AccessGrant;

public class SocialConnectionFactory extends OAuth2ConnectionFactory<SocialApi> {
  private SocialServiceProvider serviceProvider;
  
  private SocialApiAdapter apiAdapter;
  
  public SocialConnectionFactory(Provider provider, SocialServiceProvider serviceProvider, SocialApiAdapter apiAdapter) {
    super(provider.getProviderId(), serviceProvider, apiAdapter);
    this.serviceProvider = serviceProvider;
    this.apiAdapter = apiAdapter;
  }
  
  public SocialTemplate getOAuthOperations() {
    return (SocialTemplate)this.serviceProvider.getOAuthOperations();
  }
  
  protected SocialServiceProvider getServiceProvider() {
    return this.serviceProvider;
  }
  
  protected SocialApiAdapter getApiAdapter() {
    return this.apiAdapter;
  }
  
  public Connection<SocialApi> createConnection(AccessGrant accessGrant) {
    return super.createConnection(accessGrant);
  }
  
  public Connection<SocialApi> createConnection(ConnectionData data) {
    return super.createConnection(data);
  }
}
